package com.example.hyw.szysteam.presenter;

import com.example.hyw.szysteam.POJO.HomeWork;
import com.example.hyw.szysteam.POJO.HttpResult;
import com.example.hyw.szysteam.model.HomeWorkModel;
import com.example.hyw.szysteam.view.ClassWorkFragment;

import java.util.ArrayList;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by HYW on 2018/6/26.
 */

public class GetHomeWorkPresenter {
    HomeWorkModel homeWorkModel=new HomeWorkModel();
    ClassWorkFragment classWorkFragment;

    public GetHomeWorkPresenter(ClassWorkFragment classWorkFragment) {
        this.classWorkFragment = classWorkFragment;
    }

    public void getHomeWork(String classid){
        homeWorkModel.getHomeWork(classid)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<HttpResult<ArrayList<HomeWork>>>() {
                    @Override
                    public void accept(HttpResult<ArrayList<HomeWork>> arrayListHttpResult) throws Exception {
                        ArrayList<HomeWork> homeWork=arrayListHttpResult.getContent();
                        classWorkFragment.initListView(homeWork);
                    }
                });
    }
}
